package com.test;

/**
 * Created by lenovo on 2017/3/30.
 * 快速排序
 */
public class QuickSort {
    int[] QuickSortFunc (int prams[]){

       if(prams.length>0){
            QuickSort(prams,0,prams.length-1);
       }
        return prams;
    }

    public void QuickSort(int arrs[],int start,int end){
        if(start<end){
            int middle = GetMiddle(arrs,start,end);
            QuickSort(arrs,start,middle-1);
            QuickSort(arrs,middle+1,end);
        }
    }
    /*将*/
    public int GetMiddle(int arrs[],int start,int end){
        int temp  = arrs[start];
        while (start<end){
            while(start<end && arrs[end]>=temp){
                end--;
            }
            arrs[start] = arrs[end];
            while (start<end && arrs[start]<=temp){
                start++;
            }
            arrs[end] =arrs[start];
        }
        arrs[start] = temp;
        return start;
    }

    public static void main(String args[]){
        int[] prams={12,1,3,4,2,1,5,7,4,7,3,4,9,0,7,6,8};
        QuickSort QS = new QuickSort();
        int[] result = QS.QuickSortFunc(prams);
        for (int i=0;i<result.length;i++){
            System.out.print(prams[i]);
        }
    }
}
